package org.parademo.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

/**
 * @author Ajit Skanda
 * @version 1.0
 */
public class ProposalEntity extends Entity {

    private String title;
    private String description;
    private boolean internal;
    private Date votingStartDate;
    private Date votingEndDate;
    private Category category;
    private MemberEntity author;
    private ProposalStatus status;
    private ArrayList<VoteEntity> votes = new ArrayList<VoteEntity>();

    public ProposalEntity() {
    }

    public ProposalEntity(String pTitle, String pDesc, Date pVoteStartDate, Date pVoteEndDate,
                          Category pCategory, MemberEntity pAuthor, ProposalStatus pStatus) {
        id = new Random().nextLong();
        title = pTitle;
        description = pDesc;
        votingStartDate = pVoteStartDate;
        votingEndDate = pVoteEndDate;
        category = pCategory;
        author = pAuthor;
        status = pStatus;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String pTitle) {
        String oldTitle = title;
        title = pTitle;
        pcs.firePropertyChange("title", oldTitle, pTitle);
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String pDescription) {
        String oldDesc = description;
        description = pDescription;
        pcs.firePropertyChange("description", oldDesc, pDescription);
    }

    public boolean isInternal() {
        return internal;
    }

    public void setInternal(boolean pInternal) {
        boolean oldInternal = internal;
        internal = pInternal;
        pcs.firePropertyChange("internal", oldInternal, pInternal);
    }

    public MemberEntity getAuthor() {
        return author;
    }

    public void setAuthor(MemberEntity pAuthor) {
        MemberEntity oldAuthor = author;
        this.author = pAuthor;
        pcs.firePropertyChange("author", oldAuthor, pAuthor);
    }

    public Date getVotingStartDate() {
        return votingStartDate;
    }

    public void setVotingStartDate(Date pVotingStartDate) {
        Date oldVotingStartDate = votingStartDate;
        votingStartDate = pVotingStartDate;
        pcs.firePropertyChange("votingStartDate", oldVotingStartDate, pVotingStartDate);
    }

    public Date getVotingEndDate() {
        return votingEndDate;
    }

    public void setVotingEndDate(Date pVotingEndDate) {
        Date oldVotingEndDate = votingEndDate;
        votingEndDate = pVotingEndDate;
        pcs.firePropertyChange("votingEndDate", oldVotingEndDate, pVotingEndDate);
    }

    public ProposalStatus getStatus() {
        return status;
    }

    public void setStatus(ProposalStatus pStatus) {
        ProposalStatus oldStatus = status;
        status = pStatus;
        pcs.firePropertyChange("status", oldStatus, pStatus);
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category pCategory) {
        Category oldCategory = category;
        category = pCategory;
        pcs.firePropertyChange("category", oldCategory, pCategory);
    }

    public String getCategoryString() {
        return category.name();
    }

    public void setCategoryFromString(String pCategoryStr) {
        Category oldCategory = category;
        category = Category.fromString(pCategoryStr);
        pcs.firePropertyChange("category", oldCategory, category);
    }

    public ArrayList<VoteEntity> getVotes() {
        return votes;
    }

    public void setVotes(ArrayList<VoteEntity> pVotes) {
        ArrayList<VoteEntity> oldVotes = votes;
        votes = pVotes;
        pcs.firePropertyChange("votes", oldVotes, pVotes);
    }

    @Override
    public String toString() {
        return "ProposalEntity{" +
                "id='" + id + '\'' +
                ", title='" + title + '\'' +
                ", description='" + description + '\'' +
                ", internal=" + internal +
                ", category=" + category +
                ", author=" + author +
                ", status=" + status +
                ", votingStartDate=" + votingStartDate +
                ", votingEndDate=" + votingEndDate +
                '}';
    }
}
